-- record_num
--
local import = import
---@type behavior_ret
local bret = import('bt/bt_plugin/behavior3/behavior_ret')
---@type RECORD_NUM_TYPE
local RECORD_NUM_TYPE = import('bt/custom_node/enum_type_cfg/RECORD_NUM_TYPE')
local M = {
    name = "record_num",
    type = "Action",
    desc = "通过变量名字记录次数",
    args = {
        {
            name = "str",
            type = "enum",
            desc = "执行类型",
            options = RECORD_NUM_TYPE
        },
        { 'setTimes', 'int?', "设置次数(默认是递增)" }
    },
}

function M.run(node, env, value)
    local owner = env.owner
    local name = node.args.str
    local setTime = node.args.setTimes
    if owner.recordData[name] then
        owner.recordData[name] = owner.recordData[name] + 1
    else
        owner.recordData[name] = 1
    end
    if setTime then
        owner.recordData[name] = setTime
    end

    return bret.SUCCESS
end

return M
